<?php
// .-----------------------------------------------------------------------------------
// | WE TRY THE BEST WAY
// |-----------------------------------------------------------------------------------
// | Author: 贝贝 <hebiduhebi@163.com>
// | Copyright (c) 2013-2015, http://www.gooraye.net. All Rights Reserved.
// |-----------------------------------------------------------------------------------

namespace Admin\Api;

use Admin\Model\PurifierModel;
use Common\Api\Api;

class PurifierApi extends Api{

    /**
     * 添加
     */
    const ADD = "Admin/Purifier/add";
    /**
     * 保存
     */
    const SAVE = "Admin/Purifier/save";
    /**
     * 保存根据ID主键
     */
    const SAVE_BY_ID = "Admin/Purifier/saveByID";

    /**
     * 删除
     */
    const DELETE = "Admin/Purifier/delete";

    /**
     * 查询
     */
    const QUERY = "Admin/Purifier/query";
    /**
     * 查询一条数据
     */
    const GET_INFO = "Admin/Purifier/getInfo";
    /**
     *
     */
    const QUERY_BY_GROUP = "Admin/Purifier/queryByGroup";
	
	const QUERY_NO_PAGING = "Admin/Purifier/queryNoPaging";

    const PRETEND_DELETE = "Admin/Purifier/pretendDelete";

    const QUERY_WITH_GROUP = "Admin/Purifier/queryWithGroup";

	//初始化
	protected function _init(){
		$this->model = new PurifierModel();
	}

    public function queryWithGroup($map=null,$order=false,$fields=false){
        $query = $this->model->alias("m")->join(" __ADDRESS__ as  ma on m.address_id = ma.id  ");
        if(!is_null($map)){
            $query = $query->where($map);
        }
        if(!($order === false)){
            $query = $query->order($order);
        }
        if(!($fields === false)){
            $query = $query->field($fields);
        }
        $list = $query -> select();

        if ($list === false) {
            $error = $this -> model -> getDbError();
            return $this -> apiReturnErr($error);
        }else{
            return $this -> apiReturnSuc($list);
        }
    }


}
